<?php


/**
 * Base class that represents a query for the 'units' table.
 *
 *
 *
 * @method RcpUnitsQuery orderById($order = Criteria::ASC) Order by the id column
 * @method RcpUnitsQuery orderByParentId($order = Criteria::ASC) Order by the parent_id column
 * @method RcpUnitsQuery orderByExtId($order = Criteria::ASC) Order by the ext_id column
 * @method RcpUnitsQuery orderByNamePl($order = Criteria::ASC) Order by the name_pl column
 * @method RcpUnitsQuery orderByNameEn($order = Criteria::ASC) Order by the name_en column
 * @method RcpUnitsQuery orderByTyp($order = Criteria::ASC) Order by the typ column
 * @method RcpUnitsQuery orderByMarka($order = Criteria::ASC) Order by the marka column
 * @method RcpUnitsQuery orderByLastModified($order = Criteria::ASC) Order by the last_modified column
 * @method RcpUnitsQuery orderByCreated($order = Criteria::ASC) Order by the created column
 *
 * @method RcpUnitsQuery groupById() Group by the id column
 * @method RcpUnitsQuery groupByParentId() Group by the parent_id column
 * @method RcpUnitsQuery groupByExtId() Group by the ext_id column
 * @method RcpUnitsQuery groupByNamePl() Group by the name_pl column
 * @method RcpUnitsQuery groupByNameEn() Group by the name_en column
 * @method RcpUnitsQuery groupByTyp() Group by the typ column
 * @method RcpUnitsQuery groupByMarka() Group by the marka column
 * @method RcpUnitsQuery groupByLastModified() Group by the last_modified column
 * @method RcpUnitsQuery groupByCreated() Group by the created column
 *
 * @method RcpUnitsQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method RcpUnitsQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method RcpUnitsQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method RcpUnitsQuery leftJoinUnitsRelatedByParentId($relationAlias = null) Adds a LEFT JOIN clause to the query using the UnitsRelatedByParentId relation
 * @method RcpUnitsQuery rightJoinUnitsRelatedByParentId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UnitsRelatedByParentId relation
 * @method RcpUnitsQuery innerJoinUnitsRelatedByParentId($relationAlias = null) Adds a INNER JOIN clause to the query using the UnitsRelatedByParentId relation
 *
 * @method RcpUnitsQuery leftJoinUsers($relationAlias = null) Adds a LEFT JOIN clause to the query using the Users relation
 * @method RcpUnitsQuery rightJoinUsers($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Users relation
 * @method RcpUnitsQuery innerJoinUsers($relationAlias = null) Adds a INNER JOIN clause to the query using the Users relation
 *
 * @method RcpUnitsQuery leftJoinUnitsRelatedById($relationAlias = null) Adds a LEFT JOIN clause to the query using the UnitsRelatedById relation
 * @method RcpUnitsQuery rightJoinUnitsRelatedById($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UnitsRelatedById relation
 * @method RcpUnitsQuery innerJoinUnitsRelatedById($relationAlias = null) Adds a INNER JOIN clause to the query using the UnitsRelatedById relation
 *
 * @method RcpUnits findOne(PropelPDO $con = null) Return the first RcpUnits matching the query
 * @method RcpUnits findOneOrCreate(PropelPDO $con = null) Return the first RcpUnits matching the query, or a new RcpUnits object populated from the query conditions when no match is found
 *
 * @method RcpUnits findOneById(int $id) Return the first RcpUnits filtered by the id column
 * @method RcpUnits findOneByParentId(int $parent_id) Return the first RcpUnits filtered by the parent_id column
 * @method RcpUnits findOneByExtId(string $ext_id) Return the first RcpUnits filtered by the ext_id column
 * @method RcpUnits findOneByNamePl(string $name_pl) Return the first RcpUnits filtered by the name_pl column
 * @method RcpUnits findOneByNameEn(string $name_en) Return the first RcpUnits filtered by the name_en column
 * @method RcpUnits findOneByTyp(string $typ) Return the first RcpUnits filtered by the typ column
 * @method RcpUnits findOneByMarka(string $marka) Return the first RcpUnits filtered by the marka column
 * @method RcpUnits findOneByLastModified(string $last_modified) Return the first RcpUnits filtered by the last_modified column
 * @method RcpUnits findOneByCreated(string $created) Return the first RcpUnits filtered by the created column
 *
 * @method array findById(int $id) Return RcpUnits objects filtered by the id column
 * @method array findByParentId(int $parent_id) Return RcpUnits objects filtered by the parent_id column
 * @method array findByExtId(string $ext_id) Return RcpUnits objects filtered by the ext_id column
 * @method array findByNamePl(string $name_pl) Return RcpUnits objects filtered by the name_pl column
 * @method array findByNameEn(string $name_en) Return RcpUnits objects filtered by the name_en column
 * @method array findByTyp(string $typ) Return RcpUnits objects filtered by the typ column
 * @method array findByMarka(string $marka) Return RcpUnits objects filtered by the marka column
 * @method array findByLastModified(string $last_modified) Return RcpUnits objects filtered by the last_modified column
 * @method array findByCreated(string $created) Return RcpUnits objects filtered by the created column
 *
 * @package    propel.generator.rcp.om
 */
abstract class RcpBaseUnitsQuery extends ModelCriteria
{
    /**
     * Initializes internal state of RcpBaseUnitsQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'vgp_rcp', $modelName = 'RcpUnits', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new RcpUnitsQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     RcpUnitsQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return RcpUnitsQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof RcpUnitsQuery) {
            return $criteria;
        }
        $query = new RcpUnitsQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   RcpUnits|RcpUnits[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = RcpUnitsPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(RcpUnitsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return   RcpUnits A model object, or null if the key is not found
     * @throws   PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT ID, PARENT_ID, EXT_ID, NAME_PL, NAME_EN, TYP, MARKA, LAST_MODIFIED, CREATED FROM units WHERE ID = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new RcpUnits();
            $obj->hydrate($row);
            RcpUnitsPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return RcpUnits|RcpUnits[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|RcpUnits[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(RcpUnitsPeer::ID, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(RcpUnitsPeer::ID, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the id column
     *
     * Example usage:
     * <code>
     * $query->filterById(1234); // WHERE id = 1234
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
     * $query->filterById(array('min' => 12)); // WHERE id > 12
     * </code>
     *
     * @param     mixed $id The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterById($id = null, $comparison = null)
    {
        if (is_array($id) && null === $comparison) {
            $comparison = Criteria::IN;
        }

        return $this->addUsingAlias(RcpUnitsPeer::ID, $id, $comparison);
    }

    /**
     * Filter the query on the parent_id column
     *
     * Example usage:
     * <code>
     * $query->filterByParentId(1234); // WHERE parent_id = 1234
     * $query->filterByParentId(array(12, 34)); // WHERE parent_id IN (12, 34)
     * $query->filterByParentId(array('min' => 12)); // WHERE parent_id > 12
     * </code>
     *
     * @see       filterByUnitsRelatedByParentId()
     *
     * @param     mixed $parentId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByParentId($parentId = null, $comparison = null)
    {
        if (is_array($parentId)) {
            $useMinMax = false;
            if (isset($parentId['min'])) {
                $this->addUsingAlias(RcpUnitsPeer::PARENT_ID, $parentId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($parentId['max'])) {
                $this->addUsingAlias(RcpUnitsPeer::PARENT_ID, $parentId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::PARENT_ID, $parentId, $comparison);
    }

    /**
     * Filter the query on the ext_id column
     *
     * Example usage:
     * <code>
     * $query->filterByExtId('fooValue');   // WHERE ext_id = 'fooValue'
     * $query->filterByExtId('%fooValue%'); // WHERE ext_id LIKE '%fooValue%'
     * </code>
     *
     * @param     string $extId The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByExtId($extId = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($extId)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $extId)) {
                $extId = str_replace('*', '%', $extId);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::EXT_ID, $extId, $comparison);
    }

    /**
     * Filter the query on the name_pl column
     *
     * Example usage:
     * <code>
     * $query->filterByNamePl('fooValue');   // WHERE name_pl = 'fooValue'
     * $query->filterByNamePl('%fooValue%'); // WHERE name_pl LIKE '%fooValue%'
     * </code>
     *
     * @param     string $namePl The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByNamePl($namePl = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($namePl)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $namePl)) {
                $namePl = str_replace('*', '%', $namePl);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::NAME_PL, $namePl, $comparison);
    }

    /**
     * Filter the query on the name_en column
     *
     * Example usage:
     * <code>
     * $query->filterByNameEn('fooValue');   // WHERE name_en = 'fooValue'
     * $query->filterByNameEn('%fooValue%'); // WHERE name_en LIKE '%fooValue%'
     * </code>
     *
     * @param     string $nameEn The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByNameEn($nameEn = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($nameEn)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $nameEn)) {
                $nameEn = str_replace('*', '%', $nameEn);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::NAME_EN, $nameEn, $comparison);
    }

    /**
     * Filter the query on the typ column
     *
     * Example usage:
     * <code>
     * $query->filterByTyp('fooValue');   // WHERE typ = 'fooValue'
     * $query->filterByTyp('%fooValue%'); // WHERE typ LIKE '%fooValue%'
     * </code>
     *
     * @param     string $typ The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByTyp($typ = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($typ)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $typ)) {
                $typ = str_replace('*', '%', $typ);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::TYP, $typ, $comparison);
    }

    /**
     * Filter the query on the marka column
     *
     * Example usage:
     * <code>
     * $query->filterByMarka('fooValue');   // WHERE marka = 'fooValue'
     * $query->filterByMarka('%fooValue%'); // WHERE marka LIKE '%fooValue%'
     * </code>
     *
     * @param     string $marka The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByMarka($marka = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($marka)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $marka)) {
                $marka = str_replace('*', '%', $marka);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::MARKA, $marka, $comparison);
    }

    /**
     * Filter the query on the last_modified column
     *
     * Example usage:
     * <code>
     * $query->filterByLastModified('2011-03-14'); // WHERE last_modified = '2011-03-14'
     * $query->filterByLastModified('now'); // WHERE last_modified = '2011-03-14'
     * $query->filterByLastModified(array('max' => 'yesterday')); // WHERE last_modified > '2011-03-13'
     * </code>
     *
     * @param     mixed $lastModified The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByLastModified($lastModified = null, $comparison = null)
    {
        if (is_array($lastModified)) {
            $useMinMax = false;
            if (isset($lastModified['min'])) {
                $this->addUsingAlias(RcpUnitsPeer::LAST_MODIFIED, $lastModified['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($lastModified['max'])) {
                $this->addUsingAlias(RcpUnitsPeer::LAST_MODIFIED, $lastModified['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::LAST_MODIFIED, $lastModified, $comparison);
    }

    /**
     * Filter the query on the created column
     *
     * Example usage:
     * <code>
     * $query->filterByCreated('2011-03-14'); // WHERE created = '2011-03-14'
     * $query->filterByCreated('now'); // WHERE created = '2011-03-14'
     * $query->filterByCreated(array('max' => 'yesterday')); // WHERE created > '2011-03-13'
     * </code>
     *
     * @param     mixed $created The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function filterByCreated($created = null, $comparison = null)
    {
        if (is_array($created)) {
            $useMinMax = false;
            if (isset($created['min'])) {
                $this->addUsingAlias(RcpUnitsPeer::CREATED, $created['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($created['max'])) {
                $this->addUsingAlias(RcpUnitsPeer::CREATED, $created['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(RcpUnitsPeer::CREATED, $created, $comparison);
    }

    /**
     * Filter the query by a related RcpUnits object
     *
     * @param   RcpUnits|PropelObjectCollection $units The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   RcpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUnitsRelatedByParentId($units, $comparison = null)
    {
        if ($units instanceof RcpUnits) {
            return $this
                ->addUsingAlias(RcpUnitsPeer::PARENT_ID, $units->getId(), $comparison);
        } elseif ($units instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(RcpUnitsPeer::PARENT_ID, $units->toKeyValue('PrimaryKey', 'Id'), $comparison);
        } else {
            throw new PropelException('filterByUnitsRelatedByParentId() only accepts arguments of type RcpUnits or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UnitsRelatedByParentId relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function joinUnitsRelatedByParentId($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UnitsRelatedByParentId');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UnitsRelatedByParentId');
        }

        return $this;
    }

    /**
     * Use the UnitsRelatedByParentId relation Units object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   RcpUnitsQuery A secondary query class using the current class as primary query
     */
    public function useUnitsRelatedByParentIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinUnitsRelatedByParentId($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UnitsRelatedByParentId', 'RcpUnitsQuery');
    }

    /**
     * Filter the query by a related RcpUsers object
     *
     * @param   RcpUsers|PropelObjectCollection $users  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   RcpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUsers($users, $comparison = null)
    {
        if ($users instanceof RcpUsers) {
            return $this
                ->addUsingAlias(RcpUnitsPeer::ID, $users->getUnitId(), $comparison);
        } elseif ($users instanceof PropelObjectCollection) {
            return $this
                ->useUsersQuery()
                ->filterByPrimaryKeys($users->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByUsers() only accepts arguments of type RcpUsers or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Users relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function joinUsers($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Users');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Users');
        }

        return $this;
    }

    /**
     * Use the Users relation Users object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   RcpUsersQuery A secondary query class using the current class as primary query
     */
    public function useUsersQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinUsers($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Users', 'RcpUsersQuery');
    }

    /**
     * Filter the query by a related RcpUnits object
     *
     * @param   RcpUnits|PropelObjectCollection $units  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   RcpUnitsQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUnitsRelatedById($units, $comparison = null)
    {
        if ($units instanceof RcpUnits) {
            return $this
                ->addUsingAlias(RcpUnitsPeer::ID, $units->getParentId(), $comparison);
        } elseif ($units instanceof PropelObjectCollection) {
            return $this
                ->useUnitsRelatedByIdQuery()
                ->filterByPrimaryKeys($units->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByUnitsRelatedById() only accepts arguments of type RcpUnits or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UnitsRelatedById relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function joinUnitsRelatedById($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UnitsRelatedById');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UnitsRelatedById');
        }

        return $this;
    }

    /**
     * Use the UnitsRelatedById relation Units object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   RcpUnitsQuery A secondary query class using the current class as primary query
     */
    public function useUnitsRelatedByIdQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinUnitsRelatedById($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UnitsRelatedById', 'RcpUnitsQuery');
    }

    /**
     * Exclude object from result
     *
     * @param   RcpUnits $units Object to remove from the list of results
     *
     * @return RcpUnitsQuery The current query, for fluid interface
     */
    public function prune($units = null)
    {
        if ($units) {
            $this->addUsingAlias(RcpUnitsPeer::ID, $units->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
